package gis.activities;

import android.app.Activity;
import android.os.Bundle;

import com.alibaba.fastjson.JSON;
import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.HttpHeaderParser;
import com.android.volley.toolbox.StringRequest;
import com.xkh.xkh.MyApplication;
import com.xkh.xkh.R;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import gis.dto.GPS_Record;
import managers.VolleySingleton;

/**
 * Created by Administrator on 2017/5/3.
 */

public class Mapshow3 extends Activity {
    private String region;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }



    // 保存GPS信息
    public void saveGPSInfo()
    {
        String IP = MyApplication.share().getResources().getString(R.string.IP);
        String url = "http://" + IP + "/gps/SaveGPSInfo";
        StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {


                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                Map map = new HashMap();
                GPS_Record gps_record = new GPS_Record();
                gps_record.setAccount("");
                gps_record.setArea("");
                gps_record.setId(0);
                gps_record.setMiddlePoint("");
                gps_record.setRegion(0);
                gps_record.setRemark("");
                gps_record.setTime(null);
                return map;
            }

            @Override
            protected Response<String> parseNetworkResponse(NetworkResponse response) {
                String temp = null;
                try {
                    temp = new String(response.data, "utf-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                return Response.success(temp, HttpHeaderParser.parseCacheHeaders(response));
            }
        };
        VolleySingleton.getVolleySingleton(MyApplication.share()).addToRequestQueue(stringRequest);
    }


    // 更新GPS信息
    public void updateGPS()
    {
        String IP = MyApplication.share().getResources().getString(R.string.IP);
        String url = "http://" + IP + "/gps/UpdateGPSINfo";
        StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {


                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                Map map = new HashMap();
                GPS_Record gps_record = new GPS_Record();
                gps_record.setAccount("");
                gps_record.setArea("");

                gps_record.setMiddlePoint("");
                gps_record.setRegion(0);
                gps_record.setRemark("");
                gps_record.setTime(null);
                return map;
            }

            @Override
            protected Response<String> parseNetworkResponse(NetworkResponse response) {
                String temp = null;
                try {
                    temp = new String(response.data, "utf-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                return Response.success(temp, HttpHeaderParser.parseCacheHeaders(response));
            }
        };
        VolleySingleton.getVolleySingleton(MyApplication.share()).addToRequestQueue(stringRequest);
    }


    // 获取到所在区的历史记录
    public void getGPSNear()
    {
        String IP = MyApplication.share().getResources().getString(R.string.IP);
        String url = "http://" + IP + "/gps/UpdateGPSINfo";
        StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {


                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                Map map = new HashMap();
                map.put("region",region);
                return map;
            }

            @Override
            protected Response<String> parseNetworkResponse(NetworkResponse response) {
                String temp = null;
                try {
                    temp = new String(response.data, "utf-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                return Response.success(temp, HttpHeaderParser.parseCacheHeaders(response));
            }
        };
        VolleySingleton.getVolleySingleton(MyApplication.share()).addToRequestQueue(stringRequest);
    }
}
